// pages/function/video/info/info.js

Page({

  /**
   * 页面的初始数据
   */
  data: {
    videosrc: "",
    videoid: '',
    homework: []

  },
  homework(event) {
    wx.navigateTo({
      url: '../../../work/work'
    })
  },
  show(event) {
    wx.navigateTo({
      url: '../show/show?id='+event.currentTarget.dataset.id
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this
    const res = wx.getStorageSync('videoid_key')
    this.setData({
      videoid: res
    })
    // console.log(res);
    // console.log(this.data.videoid);
    var url = decodeURIComponent(options.src)

    this.setData({
      videosrc: url
    })

    wx.request({
      url: 'http://127.0.0.1:8110/admin/edu/homework/list/' + this.data.videoid,
      success: function (res) {
        console.log(res);
        console.log(res.data.data.homeworks);
        for (var i = 0; i < res.data.data.homeworks.length; i++) {
          var newarray = {
            id: res.data.data.homeworks[i].id,
            gmtCreate: res.data.data.homeworks[i].gmtCreate.replace(/T/g, ' ').replace(/\.[\d]{3}Z/, ''),
            nickName: res.data.data.homeworks[i].nickName,
            status: res.data.data.homeworks[i].status,
            value: res.data.data.homeworks[i].value,
          };
          that.data.homework = that.data.homework.concat(newarray);
          that.setData({
            homework: that.data.homework
          });
        }
        //  that.setData({
        //   homework: res.data.data.homeworks
        // })
        // var test=res.data.data.homeworks.forEach(function(item, index){
        //  //这里的item就是从数组里拿出来的每一个每一组
        //    item.gmtCreate=item.gmtCreate.replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '');
        //  console.log(str);
        // that.setData({
        //   gmtCreate: str,

        // })
        // })

      }
    })
    if (!wx.getStorageSync('openid_key')) {
      wx.navigateTo({
        url: '../../../login/index/index',
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})